﻿/**
 *	(C) 2014 Yuanjj
 *
 *	define opt class
 *
 *	histroy
 * 		2014-08-04	Yuanjj		-	create
 */

#ifndef _OPT_H_
#define _OPT_H_

#include "typedef.h"
#include "define.h"
#include <QXmlStreamReader>
#include <QFile>

/**
 *	option data struct
 */
typedef struct _opt_info
{
    // global
    pem_s8_t		g_path[256];	// the exe path
    pem_s32_t		g_level;		// the log level

    // option for db
    pem_s8_t		db_ip[16];		// data base host ip address
    pem_u16_t		db_port;		// data base port
    pem_s8_t		db_user[32];	// data base user
    pem_s8_t		db_passwd[32];	// data base user pass word
    pem_s8_t		db_name[32];	// data base name
    pem_s8_t		db_set[16];		// data base connect character set

    // option for net
    pem_s8_t		net_shlib[256];		// share lib path
} opt_info;

/**
 *	option data class
 */
class cls_opt
{
public:
    cls_opt();
    ~cls_opt();

protected:
    MUTEX_LOCK		m_lock;			// option data lock
    opt_info		m_opt;			// option data

public:
    /**
     *	initialize the option data
     */
    pem_error_t		instance();

    /**
     *	release option data
     */
    pem_void_t		release();

    /**
     *	copy the opt_info object out
     *
     * 	@opt		[out] the opt_info object
     */
    pem_void_t		get_opt( opt_info& opt );

    /**
     *	get log level
     *
     * 	return
     * 		the log level
     */
    pem_s32_t		get_log_level();

protected:
    /**
     * 	get exe path
     */
    pem_error_t		_get_exe_path();

    /**
     *	load optiong file
     */
    pem_error_t		_load_option_file();

    /**
     *	read data base option
     */
    pem_void_t		_read_db( QXmlStreamReader& xml );

    /**
     *	read data base option
     */
    pem_void_t		_read_net( QXmlStreamReader& xml );
};

#endif // _OPT_H_
